package com.xfhy.componentbase;

import com.xfhy.componentbase.empty_service.EmptyAccountService;
import com.xfhy.componentbase.service.IAccountService;

/**
 * @author : xfhy
 * Create time : 2020-03-01 11:13
 * Description : 单例 用于创建和获取每个组件对外提供的Service接口,从而实现跨组件调用方法和传递数据
 *
 * 基于接口编程
 *
 */
public class ServiceFactory {

    private IAccountService mAccountService;

    private ServiceFactory() {
    }

    private static class Inner {
        private static final ServiceFactory INSTANCE = new ServiceFactory();
    }

    public static ServiceFactory getInstance() {
        return Inner.INSTANCE;
    }

    /**
     * 接收Login组件实现的Service实例
     */
    public void setAccountService(IAccountService accountService) {
        mAccountService = accountService;
    }

    /**
     * 返回Login组件的Service实例
     */
    public IAccountService getAccountService() {
        //提供默认实现
        if (mAccountService == null) {
            mAccountService = new EmptyAccountService();
        }
        return mAccountService;
    }

}
